home *** CD-ROM | disk | FTP | other *** search
- /*
- * Newsgroups: comp.sys.sgi
- * Subject: Re: Wanted: traceback subroutine
- * Summary: Common man's approach
- * Date: 18 Jul 91 21:50:03 GMT
- *
- * Without any knowledge of the stack, the common person can ask dbx to
- * do a stack trace from his program. Here is an simple test case:
- *
- * It's much more expensive, of course.
- * compile cc test.c , a.out
- */
- #include <stdio.h>
- #include <signal.h>
- extern char *sys_errlist[];
- extern int sys_nerr;
- #define DIED -1
- int proc3(i,j)
- int i,j;
- {
- int mypid, errno, termsig;
- static char *dbxstring = " ";
- static char *createfile =" ";
- static char *filename = "/tmp/tttttttttt";
- static char *rmfile = " ";
- int irr;
- mypid = getpid();
- sprintf(filename + 7, "%d" , mypid);
- sprintf (dbxstring, "echo \"where\nquit\" | dbx -p %d 1>&2",mypid);
- sprintf (createfile, "echo \"where\nquit\" > %s",filename);
- sprintf (rmfile, "rm -rf %s",filename);
- irr = system (dbxstring);
- if (irr != 0)
- perror ("Unable to call dbx for trace");
- if (system (rmfile) < 0)
- fprintf (stderr, "Error unable to remove temp file: %s\n", filename);
- return (0);
- }
- proc2(i,j)
- int i,j;
- {
- int kk;
- kk = proc3(j,i);
- if (kk == 0)
- printf ("successfull return from trace\n");
- }
- main()
- {
- int i,j;
- i = 10;
- j = 12;
- proc2(i,j);
- }
-